<?php

namespace backend\modules\Sys\modules\CommonResource\modules\Attachment;

use Yii;

/**
 * attachment module definition class
 */
class Module extends \yii\base\Module
{
    /**
     * @inheritdoc
     */
    protected $_organizer;
    protected $_userDirPath;
    protected $_storePath;
    public $controllerNamespace = 'backend\modules\Sys\modules\CommonResource\modules\Attachment\controllers';

    public function init() {
        parent::init();

        $this->_organizer = Yii::$app->folderOrganizer;
        $this->defaultRoute = 'file';
    }

    /**
     * generate file path in time
     * @param $fileHash
     * @return string
     */
    public function getStorePath() {
        if (is_null($this->_storePath)) {
            $this->_storePath = $this->_organizer->getUploadStorePath();
        }
        return $this->_storePath;
    }

    /**
     * generate file path in time
     * @param $fileHash
     * @return string
     */
    public function getFileDirPath($fileHash, $entityModel = null) {
        return $this->_organizer->getFullUploadStoreDir($fileHash, $entityModel);
    }

    /**
     * generate logic path in time
     * @param type $fileHash
     * @param type $entityModel
     * @return type
     */
    public function getFileLogicPath($fileHash, $entityModel = null) {
        return $this->_organizer->getUploadLogicPath($fileHash, $entityModel);
    }

    public function getUserDirPath() {
        if (is_null($this->_userDirPath)) {
            $this->_userDirPath = $this->_organizer->getUserTempDirPath();
        }
        return $this->_userDirPath;
    }
}
